<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.限时促销活动</title>
<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="shortcut icon" href="include/images/icss.ico"
	type="image/x-icon" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/global.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/style.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/pro.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/proManage.css" />
<link rel="stylesheet"
	href="<%=path%>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css"
	type="text/css"></link>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/include/css/mmt_trading.css" />
<script type="text/javascript"
	src="<%=path%>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.busin.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/JQuery ui/js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/icss.common.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript"
	src="<%=path%>/include/pagination/init.js"></script>
<script src="<%=path%>/include/DatePicker/WdatePicker.js"
	charset="UTF-8" type="text/javascript"></script>
<style type="text/css">
.price a.price_rise {
	background-position: -62px -136px;
}

.price a.price_drop {
	background-position: -62px -95px;
}

.price a.price_null {
	background-position: -1px -280px;
	padding-right: 0px;
}

.expire a.expire_drops {
	background-position: -61px -95px;
}

.expire a.expire_rise {
	background-position: -61px -136px;
}

.expire a.expire_null {
	background-position: -61px -15px;
	padding-right: 0px;
}

em.create {
	background-position: -50px -44px;
	line-height: 28px;
	display: inline-block;
	font-style: normal;
	background-repeat: no-repeat;
	text-indent: 15px;
	float: right;
	cursor: pointer;
}

.create {
	background: url("<%=path%>/images/coupons/sort_zss.png");
}

#listTable th {
	line-height: 30px;
	border: 1px solid #ddd;
	font-weight: bold;
}

#ajaxSerieslist td {
	border: 1px solid #ddd;
	line-height: 40px;
}
.search_lis_se input{
height: 24px;
}
</style>

<script type="text/javascript">
$(document).ready(function() {
	_reHeight("rightFrame","contentDiv");

	_queryList();
	
});

	function shouDialog(){
		$("#dialogDiv").dialog("open");
	}

	//处理查询条件的默认值
    //参数：id;ovalue原值;nvalue 新值; type：事件类型（1表示获取焦点 2表示失去焦点）
    function clearDefaultVal(id,type,ovalue,nvalue){
        if(type==1){//判断事件类型(获取焦点,情况现有默认值)
            jQuery("#"+id).val("");
        }else{
            //失去焦点，值为空，赋默认值
            if(nvalue==""){
                jQuery("#"+id).val(ovalue);
            }
        }
    }

    function _toPromotion(){
    	window.location.href ="<%=path%>/promotion/toPromotionPage.do?flag=add";
    }
    function _edit(id){
    	window.location.href ="<%=path%>/promotion/toPromotionPage.do?flag=edit&promotionId="+id;
    }
    function _info(id){
    	window.location.href ="<%=path%>/promotion/toPromotionPage.do?flag=info&promotionId="+id;
    }
    function _del(id){
       parent.swal({
			title: "确认是否删除吗？", 
			type: "warning",
			showCancelButton: true,
			closeOnConfirm: false,
			cancelButtonText: "取消",
			cancelButtonColor: "#ec6c62",
			confirmButtonText: "确定",
			confirmButtonColor: "#ec6c62"
			}, function() {
				parent.swal.close();
				$.ajax({
					type:"post",
					url: "<%=path%>/promotion/del.do",
					data:{promotionId:id},
					dataType:"json",
					success:function(data){
						if(data.success){
							_queryList();
						}
					}
				});
		 });
    }
    
    var pagination;
	function _queryList(){
		var title = $("#queryTitle").val();
		if(title =="请输入活动名称..."){
			title = "";
		}
		var date =  $("#useDate").val();
		
		var url = "<%=path%>/promotion/promotionList.do?name=" + title
				+ "&date=" + date;
		pagination = _initPagination({
			'pageId' : 'pagination',
			'cKey' : 'toPromotionList',
			'url' : url,
			'rows' : 10,
			'callback' : _initDataList
		});

	}
	function _initDataList(data) {
		var d = data.rows;
		var total = data.total;
		var str = "";
		$("#ajaxSerieslist").empty();
		for (var i = 0; i < d.length; i++) {

			str += "<tr>";
			str += "    <td style='text-align:left;vertical-align: middle'>";
			str += "      <span style='padding-left: 10px;'>"
					+ d[i].PROMOTION_NAME + "</span>";
			str += "	</td>";
			str += "		<td id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
			str += " 				<span style='color: #000000'>" + d[i].BEG_TIME
					+ "</span>";
			str += " 	</td>";
			str += "		<td id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
			str += " 		<span  style='color: #000000'>" + d[i].END_TIME
					+ "</span>";
			str += " 	</td>";
			str += "		<td id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
			str += " 		<span>" + d[i].PROMOTION_RANGE + "</span>";
			str += " 	</td>";
			str += "		<td id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
			if(d[i].PROM_TYPE == '1'){
				str += " 		<span>" + d[i].PROMOTION_TYPE + "(" + d[i].PROMOTION_NUM + "折)</span>";
			}else if(d[i].PROM_TYPE == '2'){
				str += " 		<span>" + d[i].PROMOTION_TYPE + "(" + d[i].PROMOTION_NUM + "元)</span>";
			}
			str += " 	</td>";
			str += "		<td id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
			str += " 		<span>" + d[i].STATUS_NODE + "</span>";
			str += " 	</td>";
			str += " 	<td  style='text-align:center;vertical-align: middle;'><p>";
			if(d[i].STATUS=="0"){
				str += "    		<a  href='javascript:_updateStatus(\"" + d[i].PROMOTION_ID+ "\",\"1\");'>启用</a>";
				str += "    		/&nbsp;<a  href='javascript:_edit(\"" + d[i].PROMOTION_ID+ "\");'>修改</a>";
				str += "      		/&nbsp;<a href='javascript:void()' onclick=\"_del('"+ d[i].PROMOTION_ID + "')\">删除</a>";
			} else if(d[i].STATUS=="1"){
				str += "    		<a  href='javascript:_updateStatus(\"" + d[i].PROMOTION_ID+ "\",\"0\");'>禁用</a>";
				str += "    		/&nbsp;<a  href='javascript:_info(\"" + d[i].PROMOTION_ID+ "\");'>详情</a>";
			}
			str += " 	</p></td>";
			str += " </tr>";
		}
		$("#ajaxSerieslist").append(str);

	}
	function _updateStatus(promotionId,status){
		var tip="";
		var tipMsg="";
		if(status=='1'){
			tip = '确定启用吗？';
			tipMsg="启用";
		}else if(status=='0'){
			tipMsg="停用";
			tip = '确定停用吗？';
		}
		parent.swal({
			title: tip, 
			type: "warning",
			showCancelButton: true,
			closeOnConfirm: false,
			cancelButtonText: "取消",
			cancelButtonColor: "#ec6c62",
			confirmButtonText: "确定",
			confirmButtonColor: "#ec6c62"
			}, function() {
				$.ajax({
	                cache: true,
	                type: "POST",
	                url:'<%=path%>/promotion/updateStatus',
	                data:{
	                	promotionId : promotionId,
	                	status : status
	                },
	                async: false,
	                dataType:"json",
	                error: function(request) {
	                    parent.swal("","操作异常!","error");
	                },
	                success: function(data) {
						var msg = data.msg;
	                    if(data.success){
	                     	location.reload();
							parent.swal("", tipMsg+"成功", "success");
						}else {
							parent.swal("", tipMsg+"失败", "error");
						}
	                }
	           	});
		 });
	}
	function _clear(){
		$("#queryTitle").val("");
		$("#useDate").val("");
	}
</script>
</head>

<body style="font-family: '微软雅黑';">
	<div id="contentDiv" style="padding:4px; width:99%;">
		<div class="colnums-2-ab-b">
			<div class="toptil">限时促销活动</div>
			<div class="search_lis"
				style="border: 1px solid #e0e0e0;background: #f5f5f5;padding-left:6px;margin-bottom:10px;font-size:14px;width: 99%;">
				<!--search_lis S-->
				<div class="search_lis_se" style="height:26px;margin-left: 4px;">
					<!--search_lis_se S-->
					<span>活动名称:</span> <input name="querytitle" id="queryTitle"
						type="text" class="in_bit" maxlength="40" style="color:black;" > <span>活动时间:</span>
					<input type="text" id="useDate" name="useDate"
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
						style="width: 160px;height: 24px; padding-left: 3px"
						onfocus="WdatePicker({position:{left:323,top:88}})" class="Wdate"
						value="" /> &nbsp;&nbsp;
					<button type="button" class="cxx_btn" onclick="_queryList()">查询</button>
					<button type="button" class="cxx_btn" onclick="_clear()">清空</button>
					<em class="create" id="create" style="margin-right:20px"
						onclick="_toPromotion()">促销活动</em>
				</div>
			</div>
			<div class="row-fluid dataTables_wrapper" style="width:100%;">
				<table id="listTable"
					class="table table-hover table-nomargin table-bordered usertable dataTable"
					style="width: 100%; border-spacing: 0;">
					<thead>
						<tr class="trBgd"
							style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
							<th class="t2"
								style="text-align:center;vertical-align: middle;">促销名称</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">开始时间</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">结束时间</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">范围</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">类型</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">状态</th>
							<th class="t2"
								style="text-align:center;vertical-align: middle;">操作</th>
						</tr>
					</thead>
					<tbody id="ajaxSerieslist">
					</tbody>
				</table>
				<div id="pagination"></div>
			</div>
		</div>
	</div>
</body>
</html>
